import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
interface Par extends Event {
	page_no: number;
}
export default async function a006(fd: IFeidaoAiBrowserComponent, e: Par) {
	// todo
	const exam_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="exam_name"]').value;
	const res = await nodejs<{ dt: Array<{ exam_id: string, exam_name: string, exam_time: string, examination_category: string, exam_score: string, exam_time1: string, exam_caozuo: string }>; c: Array<{}> }>('employee-examination/zj-000001/s005',
		{
			filter: {
				exam_name: exam_name1,
				pn: e.page_no
			}
		});
	const a = Array();
	for (let i = 0; i < res.dt.length; i++) {
		a.push(res.dt[i].exam_id);
	}
	const res1 = await nodejs<{ dt: Array<{ exam_id: string, exam_score: string, exam_time: number }> }>('employee-examination/zj-000001/s006',
		{
			filter: {
				exam_id: a

			}
		});
	const p = res1.dt.map((n) => {
		return { ...n, exam_time: format(n.exam_time, 2) };
	});
	const dat = res.dt.map((n) => {
		for (let index = 0; index < res1.dt.length; index++) {
			if (res1.dt[index].exam_id === n.exam_id) {
				n.exam_time1 = p[index].exam_time;
				n.exam_score = res1.dt[index].exam_score;
				return n;
			}
		}
		n.exam_time1 = '';
		n.exam_score = '';
		return n;
	});
	const no = get("no");
	const res2 = await nodejs<{ dt: Array<{ exam_id: string }> }>('employee-examination/zj-000001/s002',
		{
			filter: {
				candidate_no: no
			}
		});
	const ret = new Array();
	for (let i = 0; i < res2.dt.length; i++) {
		ret[i] = res2.dt[i].exam_id;

	}
	// 数组去重
	const ses = new Set(ret);
	const newArr = Array.from(ses);
	// 操作
	const da = dat.map((n) => {
		for (let index = 0; index < newArr.length; index++) {
			if (newArr[index] === n.exam_id) {
				n.exam_caozuo = "1";
				return n;
			}
		}
		n.exam_caozuo = "0";
		return n;
	});
	// 获取那三个dot模板
	const dtData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const dtNoData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dtPn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	dtPn.style.display = 'none';
	if (da.length > 0) {
		render(fd, da, p001, 'p001', 'inner');
		dtNoData.style.display = 'none';
		dtData.style.display = 'block';
	} else {
		render(fd, '', p002, 'p002', 'inner');
		dtNoData.style.display = 'block';
		dtData.style.display = 'none';
		dtPn.style.display = 'none';

	}
}
